package com.yenlien.traceyun.plant.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.plant.dao.PlantDao;
import com.yenlien.traceyun.plant.entity.Plant;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2021-01-04
 * @description:种植扫码信息
 **/

@RestController
@RequestMapping(value = "/plant/scan")
public class PlantSanController extends BaseController {


    @Autowired
    private PlantDao plantDao;

    /**
     * 地块种植情况
     *
     * @param basesoildId
     * @return
     */
    @GetMapping(value = "/basesoil/{basesoilId}")
    public Object plantInfo(@PathVariable("basesoilId") String basesoildId) {
        JSONObject result = new JSONObject();
        List<Plant> plants = plantDao.findByReapStatusAndSoilId(2, basesoildId);
        List<Plant> plantsing = plantDao.findByReapStatusAndSoilId(0, basesoildId);
        List<Plant> plantsing2 = plantDao.findByReapStatusAndSoilId(1, basesoildId);
        plantsing.addAll(plantsing2);
        result.put("history", plants);
        result.put("planting", plantsing);
        return result;
    }
}
